import numpy as np
import matplotlib.pyplot as plt
import matplotlib
# 设置中文显示、画布大小
matplotlib.rcParams['font.family'] = "SimHei"
plt.figure(figsize=(8.0, 6.0))
# 分割圆并执行闭合操作（0-2π之间返回间隔均匀的6个弧度：π/3、2π/3、π、4π/3、5π/3、2π）
theta = np.linspace(0, 2*np.pi, 6, endpoint=False)
theta = np.concatenate((theta, [theta[0]]))
# 设置两组数据并执行闭合操作
data1 = np.array([0.40, 0.32, 0.35, 0.30, 0.30, 0.88])
data2 = np.array([0.85, 0.35, 0.30, 0.40, 0.40, 0.30])
data3 = np.array([0.43, 0.89, 0.30, 0.28, 0.22, 0.30])
data4 = np.array([0.30, 0.25, 0.48, 0.85, 0.45, 0.40])
data5 = np.array([0.20, 0.38, 0.87, 0.45, 0.32, 0.28])
data6 = np.array([0.34, 0.31, 0.38, 0.40, 0.92, 0.28])
data1 = np.concatenate((data1, [data1[0]]))
data2 = np.concatenate((data2, [data2[0]]))
data3 = np.concatenate((data3, [data3[0]]))
data4 = np.concatenate((data4, [data4[0]]))
data5 = np.concatenate((data5, [data5[0]]))
data6 = np.concatenate((data6, [data6[0]]))
# 绘制并填充两组数据
data_labels = ('艺术家', '实验员', '工程师', '推销员', '社会工作者', '记事员')
plt.polar(theta, data1, 'bo-')
plt.polar(theta, data2, 'ro-')
plt.polar(theta, data3, 'bo-')
plt.polar(theta, data4, 'bo-')
plt.polar(theta, data5, 'bo-')
plt.polar(theta, data6, 'bo-')
plt.fill(theta, data1, color='blue', alpha=0.25)
plt.fill(theta, data2, color='yellow', alpha=0.25)
plt.fill(theta, data3, color='green', alpha=0.25)
plt.fill(theta, data4, color='pink', alpha=0.25)
plt.fill(theta, data5, color='red', alpha=0.25)
plt.fill(theta, data6, color='purple', alpha=0.25)
# 将六个弧度（π/3、2π/3、π、4π/3、5π/3、2π）转换成角度，并分别设置标签
labels = np.array(['研究型(I)', '艺术型(A)', '社会型(S)', '企业型(E)', '常规型(C)', '现实型(R)'])
labels = plt.thetagrids(range(0, 360, int(360/len(labels))), labels)
# 设置刻度范围、标题、图例
plt.ylim(0, 1)
plt.title('霍兰德人格分析')
legend = plt.legend(data_labels, loc=(0.94, 0.80), labelspacing=0.1)
plt.setp(legend.get_texts(), fontsize='large')
plt.savefig('holland_radar.jpg')
plt.show()



